package Java.BlackHorse.a06ThreadTest.Test2;

import java.util.ArrayList;
import java.util.Collections;

public class MyThread extends Thread{
    ArrayList<Integer> list ;

    public MyThread(String name, ArrayList<Integer> list) {
        super(name);
        this.list = list;
    }

    public MyThread(ArrayList<Integer> list) {
        this.list = list;
    }

    @Override
    public void run() {
        while(true){
            synchronized(MyThread.class){
                if(list.size() == 0){
                    System.out.println("奖池已经被抽空了");
                    break;
                }else{
                    Collections.shuffle(list);
                    Integer get = list.remove(0);
                    System.out.println(Thread.currentThread().getName()+"抽出了"+get+"元");
                }
            }
            try {
                Thread.sleep(300);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
